﻿$(document).ready(function () {
    $('img', $('#body')[0]).live('focus', function () {
        Shadowbox.init();
    });
    // Fade out error messages when re-visiting the input item
    $('input', $('#body')[0]).live('focus', function () {
        $(this).closest('div.form-field').children('div.form-field-error').fadeOut('slow');
        $(this).closest('div.form-field-inline').children('div.form-field-error').fadeOut('slow');
        // $('a.modal').colorbox({ iframe: true, innerWidth: 425, innerHeight: 250 }); // Todo: not sure why this is here, remove?
    });
    $('input:radio', $('#body')[0]).live('change', function () {
        $(this).closest('div.form-field').children('div.form-field-error').fadeOut('slow');
        $(this).closest('div.form-field-inline').children('div.form-field-error').fadeOut('slow');
    });
    $('input:checkbox', $('#body')[0]).live('change', function () {
        $(this).closest('div.form-field').children('div.form-field-error').fadeOut('slow');
        $(this).closest('div.form-field-inline').children('div.form-field-error').fadeOut('slow');
    });
    $('textarea', $('#body')[0]).live('focus', function () {
        $(this).closest('div.form-field').children('div.form-field-error').fadeOut('slow');
        $(this).closest('div.form-field-inline').children('div.form-field-error').fadeOut('slow');
    });
    $('select', $('#body')[0]).live('click', function () {
        $(this).closest('div.form-field').children('div.form-field-error').fadeOut('slow');
        $(this).closest('div.form-field-inline').children('div.form-field-error').fadeOut('slow');
    });
    // Allow error messages to be closed by clicking on them
    $('span.field-validation-error', $('#body')[0]).live('click', function () {
        $(this).closest('div.form-field').children('div.form-field-error').fadeOut('slow');
        $(this).closest('div.form-field-inline').children('div.form-field-error').fadeOut('slow');
    });
    $('div.validation-summary-errors', $('#body')[0]).live('click', function () {
        $(this).fadeOut('slow');
    });    
});
